<?php

namespace addons\wleaflet;

use addons\wleaflet\controller\Index;
use app\common\library\Menu;
use think\Addons;

/**
 * 插件
 */
class Wleaflet extends Addons
{

    /**
     * 插件安装方法
     * @return bool
     */
    public function install()
    {

        return true;
    }

    /**
     * 插件卸载方法
     * @return bool
     */
    public function uninstall()
    {

        return true;
    }

    /**
     * 插件启用方法
     * @return bool
     */
    public function enable()
    {

        return true;
    }

    /**
     * 插件禁用方法
     * @return bool
     */
    public function disable()
    {

        return true;
    }

    /**
     * @param $params
     * 初始化config
     */
    public function configInit(&$params)
    {
        $config = get_addon_config('wleaflet');
        $defaultLayer = $config['defaultLayer']??'';
        $useDefaultLayerList = !empty($config['useDefaultLayerList'])?explode(',',$config['useDefaultLayerList']):[];
        $config['useDefaultLayerList'] = array_merge($useDefaultLayerList,[$defaultLayer]);
        $useDefaultLayerList = array_unique(array_filter($config['useDefaultLayerList']));
        $useDefaultLayerList = $useDefaultLayerList?array_values($useDefaultLayerList):[];
        $setConfig = [
            'defaultLayer' => $defaultLayer,
            'useDefaultLayerList' => $useDefaultLayerList??[],
            'defaultCenter' =>  [$config['lat'],$config['lng']],
            'zoomBase' => $config['zoomBase']??'',
            'gaodeKey' => $config['gaodeKey']??'',
            'gaodeSecurityJsCode' => $config['gaodeSecurityJsCode']??'',
            'tdtKey' => $config['tdtKey']??'',
            'tencentKey' => $config['tencentKey']??'',
            'baiduKey' => $config['baiduKey']??'',
        ];
        $params['wleaflet'] = $setConfig;
    }


}
